<?php

namespace app\admin\model\activtyc;

use think\Cache;
use think\Model;
use app\admin\model\Area;
use app\admin\model\base\Source;
class Guessing extends Model
{
    // 表名
    protected $name = 'activity_guessing';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'version_text',
        'pay_text'
    ];
    

    
    public function getVersionList()
    {
        return ['1' => __('Version 1'),'2' => __('Version 2'),'3' => __('Version 3'),'4' => __('Version 4'),'5' => __('Version 5'),'6' => __('Version 6'),'7' => __('Version 7')];
    }     

    public function getPayList()
    {
        return ['0' => __('Pay 0'),'1' => __('Pay 1'),'2' => __('Pay 2')];
    }     


    public function getVersionTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['version'];
        $list = $this->getVersionList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['pay'];
        $list = $this->getPayList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getProvinceOrderList()
    {
        if(!$list = Cache::get('arealist'))
        {
            $area = Area::field('id,name')->select();
            $area = collection($area)->toArray();
            $list = array_column($area,'name','id');
            Cache::set('areaList',$list,0);//设置0永久缓存不过期
        }
        return $list;
    }
    public function getSourceList(){
        return array_column(collection(Source::field('id,type,name,publish,z_publish')->where(['type'=>2])->select())->toArray(), 'name','id');
    }



}
